var contentH = 0; // 获得content的高度
var tabHeaderH = 0; // tab页标题高度
var queryDivH = 0; // 查询条件div高度
var tableHeadH = 0;  // dataTable表头高度
var paginatorH = 0; // dataTable分页的高度

$("#lineFaultTab").click(function(){
	paginatorH = 35;
	tableHeadH = 59;
});

$("#busFaultTab").click(function(){
	paginatorH = 35;
	tableHeadH = 59;
});

$("#transFaultTab").click(function(){
	paginatorH = 35;
	tableHeadH = 59;
});

$("#monthTab").click(function(){
	paginatorH = 0;
	tableHeadH = 59;
});

$("#yearTab").click(function(){
	paginatorH = 0;
	tableHeadH = 30;
});


$(function(){
	$.ajaxSettings.async = false;
	initElementH();
	initDataTable();
	$.ajaxSettings.async = true;
	initFaultCountYear();
	
});

// 故障源统计-故障统计Tab页js文件
function initFaultCountYear(){
	initDataTable();
	var d = new Date();
	var currentYear=d.getFullYear();
	$("#year").val(currentYear);
	$('#year').datetimepicker({
		startView: 4,
		minView:4,
		autoclose : true,
		format : 'yyyy'
	});
}

function chaneYear(){
	var year=$("#year").val();
	changeYear([ {
		name : 'year',
		value : year
	}]);
}

function adjustPaginator() {
	// 分页部分整体偏移15px，为滚动条预留位置
	$(".ui-paginator.ui-paginator-bottom").css({
		"border-top" : "0 none",
		"margin-left" : "0px",
		"margin-right" : "15px"
	});
}

function initElementH() {
	contentH = parseInt($("#main_content>.content").css("height")) - 10; // 获得content的高度,10是padding
	tabHeaderH = parseInt($(".nav.nav-tabs.pull-left ").css("height")); // tab页标题高度
	queryDivH = parseInt($(".box-header").css("height")); // 查询条件div高度
	tableHeadH = parseInt($(".ui-widget-header.ui-datatable-scrollable-header").css("height")); // dataTable表头高度
	paginatorH = 35;
}

function initDataTable() {
	adjustPaginator();
	var dataTableScrollH = contentH - tabHeaderH - queryDivH - tableHeadH - paginatorH;
	var obj = $('.ui-datatable-scrollable-body').each(function() {
		this.style.maxHeight = dataTableScrollH + "px";
		this.style.minHeight = dataTableScrollH + "px";
		/* 解决当数据无法撑满整个表格的时候，没有垂直滚动条导致数据列与表头不对齐的问题 */
		this.style.overflowY = "scroll";
	});
}
